package com.lenovo.agricultureclient.ui.dialog;

import com.lenovo.agricultureclient.AppConfig;
import com.lenovo.agricultureclient.ClientApp;
import com.lenovo.agricultureclient.request.BaseRequest;
import com.lenovo.agricultureclient.request.RequestThread;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;

/**
 * 基础对话框类
 * @author zongbingwu
 *
 */
public class AppBaseDialog extends Dialog 
{
	protected Activity mActivity;
	protected ClientApp mApp;
	//等待对话框
	protected LoadingDialog mLoadDig;
	
	public AppBaseDialog(Activity act, ClientApp app)
    {
    	super(act);
    	this.mActivity = act;
    	this.mApp = app;
    }
	
	protected String getString(int reId)
    {
    	return mActivity.getString(reId);
    }
	//显示等待对话框
	protected void showLoadDialog()
	{
		if(mLoadDig == null)
		{
			mLoadDig = new LoadingDialog();
			mLoadDig.setStyle(DialogFragment.STYLE_NO_FRAME, 0); 
		}
		mLoadDig.show(mActivity.getFragmentManager(), "dialog");
	}
	//关闭对话框
	protected void dismissLoadDialog()
	{
		if(mLoadDig != null)
		{
			mLoadDig.dismiss();
		}
	}
	//显示提示框
	protected void showAlertDialog(String title, String message)
	{
		AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton(getString(android.R.string.ok), null);
		builder.show();
	}
	//开启一次性的请求线程，请求结束以后，线程就停止
	protected void startRequest(BaseRequest request)
	{
		if(request != null)
		{
			RequestThread thread = new RequestThread(AppConfig.COMMUN_TYPE, mActivity.getApplicationContext(), mApp.getHandler());
	    	thread.setRequest(request);
	    	thread.start();
		}
	}
}
